<script setup lang="ts">
import { ref } from 'vue';
import { useRouter } from 'vue-router';

const BASE_PATH = import.meta.env.VITE_API_BASE_PATH;
const router = useRouter();

// 用户名设置
const username = ref(localStorage.getItem('username') || '');
const setUsername = () => {
  if (username.value.trim()) {
    localStorage.setItem('username', username.value.trim());
  }
};

// 返回主页
const goBack = () => {
  router.push({ path: BASE_PATH + '/' });
};
</script>

<template>
  <div class="settings-container">
    <h1 class="settings-title">设 置</h1>
    
    <div class="settings-form">
      <!-- 用户名设置 -->
      <div class="settings-item">
        <label for="username" class="settings-label">用户名</label>
        <t-input 
          id="username" 
          v-model="username" 
          placeholder="请输入用户名" 
          class="settings-input"
        />
        <t-button 
          variant="base" 
          size="small" 
          @click="setUsername"
          class="settings-button"
        >
          保存
        </t-button>
      </div>
      
      <!-- 作者信息 -->
      <div class="author-info">
        <h3 class="info-title">关于我们</h3>
        <div class="info-content">
          <p>开发者: dancehole & cyanbleeze</p>
          <p>版本: v0.1.0</p>
          <p>联系方式: <a href="https://gitee.com/cyanbleeze/vue-chess/issues" target="_blank">https://gitee.com/cyanbleeze/vue-chess/issues</a></p>
          <p><a href="https://gitee.com/cyanbleeze/vue-chess#更新日志" target="_blank">更新日志</a></p>
        </div>
      </div>
    </div>
    
    <!-- 返回按钮 -->
    <t-button 
      block 
      variant="outline" 
      size="large" 
      @click="goBack"
      class="back-button"
    >
      返 回 主 页
    </t-button>
  </div>
  
  <!-- 备案信息 -->
  <div class="beian-info">
    <a href="https://beian.miit.gov.cn/" target="_blank" class="beian-link">粤ICP备2024302719号</a><br>
    <span class="copyright-text">Copyright © dancehole & cyanbleeze @2024-2025 ALL RIGHTS RESERVED</span>
  </div>
</template>

<style scoped>
.settings-container {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 500px;
  padding: 20px;
  box-sizing: border-box;
}

.settings-title {
  text-align: center;
  margin-bottom: 30px;
  color: #333;
}

.settings-form {
  background-color: #fff;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  margin-bottom: 20px;
}

.settings-item {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}

.settings-label {
  width: 80px;
  font-size: 16px;
  color: #333;
}

.settings-input {
  flex: 1;
  margin-right: 10px;
}

.settings-button {
  width: 80px;
}

.author-info {
  margin-top: 30px;
  padding-top: 20px;
  border-top: 1px solid #eee;
}

.info-title {
  color: #333;
  margin-bottom: 15px;
  text-align: center;
}

.info-content {
  color: #666;
  font-size: 14px;
  line-height: 1.6;
}

.info-content p {
  margin: 8px 0;
}

.back-button {
  margin-top: 20px;
}

/* 备案信息样式 - 保持不变 */
.beian-info {
  font-size: small;
  color: dimgrey;
  text-align: center;
  padding: 10px 0;
  position: fixed;
  bottom: 0;
  width: 100%;
}

.beian-link {
  color: dimgrey;
  text-decoration: none;
  transition: color 0.3s ease;
  margin-right: 8px;
}

.beian-link:hover {
  color: #666;
  text-decoration: underline;
}

.copyright-text {
  color: dimgrey;
  font-size: 11px;
  opacity: 0.8;
}

/* 响应式调整 */
@media (max-width: 768px) {
  .settings-container {
    width: 95%;
    padding: 15px;
  }
  
  .settings-item {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .settings-label {
    margin-bottom: 8px;
    width: 100%;
  }
  
  .settings-input {
    width: 100%;
    margin-right: 0;
    margin-bottom: 10px;
  }
  
  .settings-button {
    width: 100%;
  }
  
  .beian-info {
    font-size: 10px;
    padding: 8px 0;
  }

  .copyright-text {
    display: block;
    margin-top: 4px;
  }
}
</style>